<?php
$this->breadcrumbs=array(
	'Đặt vé sự kiện: ' . $model->title,
);
?>
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'order-form',
	'enableClientValidation'=>false,
    'enableAjaxValidation' => true,
	'htmlOptions'=>array(
		'class'=>'',
	),
)); ?>
<?php $countries = array("Việt Nam" => "Việt Nam", "Afghanistan" => "Afghanistan", "Albania" => "Albania", "Algeria" => "Algeria", "American Samoa" => "American Samoa", "Andorra" => "Andorra", "Angola" => "Angola", "Anguilla" => "Anguilla", "Antarctica" => "Antarctica", "Antigua and Barbuda" => "Antigua and Barbuda", "Argentina" => "Argentina", "Armenia" => "Armenia", "Aruba" => "Aruba", "Australia" => "Australia", "Austria" => "Austria", "Azerbaijan" => "Azerbaijan", "Bahamas" => "Bahamas", "Bahrain" => "Bahrain", "Bangladesh" => "Bangladesh", "Barbados" => "Barbados", "Belarus" => "Belarus", "Belgium" => "Belgium", "Belize" => "Belize", "Benin" => "Benin", "Bermuda" => "Bermuda", "Bhutan" => "Bhutan", "Bolivia" => "Bolivia", "Bosnia and Herzegovina" => "Bosnia and Herzegovina", "Botswana" => "Botswana", "Bouvet Island" => "Bouvet Island", "Brazil" => "Brazil", "British Indian Ocean Territory" => "British Indian Ocean Territory", "Brunei Darussalam" => "Brunei Darussalam", "Bulgaria" => "Bulgaria", "Burkina Faso" => "Burkina Faso", "Burundi" => "Burundi", "Cambodia" => "Cambodia", "Cameroon" => "Cameroon", "Canada" => "Canada", "Cape Verde" => "Cape Verde", "Cayman Islands" => "Cayman Islands", "Central African Republic" => "Central African Republic", "Chad" => "Chad", "Chile" => "Chile", "China" => "China", "Christmas Island" => "Christmas Island", "Cocos (Keeling) Islands" => "Cocos (Keeling) Islands", "Colombia" => "Colombia", "Comoros" => "Comoros", "Congo" => "Congo", "Congo, The Democratic Republic of The" => "Congo, The Democratic Republic of The", "Cook Islands" => "Cook Islands", "Costa Rica" => "Costa Rica", "Cote D'ivoire" => "Cote D'ivoire", "Croatia" => "Croatia", "Cuba" => "Cuba", "Cyprus" => "Cyprus", "Czech Republic" => "Czech Republic", "Denmark" => "Denmark", "Djibouti" => "Djibouti", "Dominica" => "Dominica", "Dominican Republic" => "Dominican Republic", "Ecuador" => "Ecuador", "Egypt" => "Egypt", "El Salvador" => "El Salvador", "Equatorial Guinea" => "Equatorial Guinea", "Eritrea" => "Eritrea", "Estonia" => "Estonia", "Ethiopia" => "Ethiopia", "Falkland Islands (Malvinas)" => "Falkland Islands (Malvinas)", "Faroe Islands" => "Faroe Islands", "Fiji" => "Fiji", "Finland" => "Finland", "France" => "France", "French Guiana" => "French Guiana", "French Polynesia" => "French Polynesia", "French Southern Territories" => "French Southern Territories", "Gabon" => "Gabon", "Gambia" => "Gambia", "Georgia" => "Georgia", "Germany" => "Germany", "Ghana" => "Ghana", "Gibraltar" => "Gibraltar", "Greece" => "Greece", "Greenland" => "Greenland", "Grenada" => "Grenada", "Guadeloupe" => "Guadeloupe", "Guam" => "Guam", "Guatemala" => "Guatemala", "Guinea" => "Guinea", "Guinea-bissau" => "Guinea-bissau", "Guyana" => "Guyana", "Haiti" => "Haiti", "Heard Island and Mcdonald Islands" => "Heard Island and Mcdonald Islands", "Holy See (Vatican City State)" => "Holy See (Vatican City State)", "Honduras" => "Honduras", "Hong Kong" => "Hong Kong", "Hungary" => "Hungary", "Iceland" => "Iceland", "India" => "India", "Indonesia" => "Indonesia", "Iran, Islamic Republic of" => "Iran, Islamic Republic of", "Iraq" => "Iraq", "Ireland" => "Ireland", "Israel" => "Israel", "Italy" => "Italy", "Jamaica" => "Jamaica", "Japan" => "Japan", "Jordan" => "Jordan", "Kazakhstan" => "Kazakhstan", "Kenya" => "Kenya", "Kiribati" => "Kiribati", "Korea, Democratic People's Republic of" => "Korea, Democratic People's Republic of", "Korea, Republic of" => "Korea, Republic of", "Kuwait" => "Kuwait", "Kyrgyzstan" => "Kyrgyzstan", "Lao People's Democratic Republic" => "Lao People's Democratic Republic", "Latvia" => "Latvia", "Lebanon" => "Lebanon", "Lesotho" => "Lesotho", "Liberia" => "Liberia", "Libyan Arab Jamahiriya" => "Libyan Arab Jamahiriya", "Liechtenstein" => "Liechtenstein", "Lithuania" => "Lithuania", "Luxembourg" => "Luxembourg", "Macao" => "Macao", "Macedonia, The Former Yugoslav Republic of" => "Macedonia, The Former Yugoslav Republic of", "Madagascar" => "Madagascar", "Malawi" => "Malawi", "Malaysia" => "Malaysia", "Maldives" => "Maldives", "Mali" => "Mali", "Malta" => "Malta", "Marshall Islands" => "Marshall Islands", "Martinique" => "Martinique", "Mauritania" => "Mauritania", "Mauritius" => "Mauritius", "Mayotte" => "Mayotte", "Mexico" => "Mexico", "Micronesia, Federated States of" => "Micronesia, Federated States of", "Moldova, Republic of" => "Moldova, Republic of", "Monaco" => "Monaco", "Mongolia" => "Mongolia", "Montserrat" => "Montserrat", "Morocco" => "Morocco", "Mozambique" => "Mozambique", "Myanmar" => "Myanmar", "Namibia" => "Namibia", "Nauru" => "Nauru", "Nepal" => "Nepal", "Netherlands" => "Netherlands", "Netherlands Antilles" => "Netherlands Antilles", "New Caledonia" => "New Caledonia", "New Zealand" => "New Zealand", "Nicaragua" => "Nicaragua", "Niger" => "Niger", "Nigeria" => "Nigeria", "Niue" => "Niue", "Norfolk Island" => "Norfolk Island", "Northern Mariana Islands" => "Northern Mariana Islands", "Norway" => "Norway", "Oman" => "Oman", "Pakistan" => "Pakistan", "Palau" => "Palau", "Palestinian Territory, Occupied" => "Palestinian Territory, Occupied", "Panama" => "Panama", "Papua New Guinea" => "Papua New Guinea", "Paraguay" => "Paraguay", "Peru" => "Peru", "Philippines" => "Philippines", "Pitcairn" => "Pitcairn", "Poland" => "Poland", "Portugal" => "Portugal", "Puerto Rico" => "Puerto Rico", "Qatar" => "Qatar", "Reunion" => "Reunion", "Romania" => "Romania", "Russian Federation" => "Russian Federation", "Rwanda" => "Rwanda", "Saint Helena" => "Saint Helena", "Saint Kitts and Nevis" => "Saint Kitts and Nevis", "Saint Lucia" => "Saint Lucia", "Saint Pierre and Miquelon" => "Saint Pierre and Miquelon", "Saint Vincent and The Grenadines" => "Saint Vincent and The Grenadines", "Samoa" => "Samoa", "San Marino" => "San Marino", "Sao Tome and Principe" => "Sao Tome and Principe", "Saudi Arabia" => "Saudi Arabia", "Senegal" => "Senegal", "Serbia and Montenegro" => "Serbia and Montenegro", "Seychelles" => "Seychelles", "Sierra Leone" => "Sierra Leone", "Singapore" => "Singapore", "Slovakia" => "Slovakia", "Slovenia" => "Slovenia", "Solomon Islands" => "Solomon Islands", "Somalia" => "Somalia", "South Africa" => "South Africa", "South Georgia and The South Sandwich Islands" => "South Georgia and The South Sandwich Islands", "Spain" => "Spain", "Sri Lanka" => "Sri Lanka", "Sudan" => "Sudan", "Suriname" => "Suriname", "Svalbard and Jan Mayen" => "Svalbard and Jan Mayen", "Swaziland" => "Swaziland", "Sweden" => "Sweden", "Switzerland" => "Switzerland", "Syrian Arab Republic" => "Syrian Arab Republic", "Taiwan, Province of China" => "Taiwan, Province of China", "Tajikistan" => "Tajikistan", "Tanzania, United Republic of" => "Tanzania, United Republic of", "Thailand" => "Thailand", "Timor-leste" => "Timor-leste", "Togo" => "Togo", "Tokelau" => "Tokelau", "Tonga" => "Tonga", "Trinidad and Tobago" => "Trinidad and Tobago", "Tunisia" => "Tunisia", "Turkey" => "Turkey", "Turkmenistan" => "Turkmenistan", "Turks and Caicos Islands" => "Turks and Caicos Islands", "Tuvalu" => "Tuvalu", "Uganda" => "Uganda", "Ukraine" => "Ukraine", "United Arab Emirates" => "United Arab Emirates", "United Kingdom" => "United Kingdom", "United States" => "United States", "United States Minor Outlying Islands" => "United States Minor Outlying Islands", "Uruguay" => "Uruguay", "Uzbekistan" => "Uzbekistan", "Vanuatu" => "Vanuatu", "Venezuela" => "Venezuela", "Viet Nam" => "Viet Nam", "Virgin Islands, British" => "Virgin Islands, British", "Virgin Islands, U.S." => "Virgin Islands, U.S.", "Wallis and Futuna" => "Wallis and Futuna", "Western Sahara" => "Western Sahara", "Yemen" => "Yemen", "Zambia" => "Zambia", "Zimbabwe" => "Zimbabwe"); ?>
<fieldset>
    <legend>Thông tin sự kiện</legend>
    <!-- Order info -->
    <div class="form-group">
        <label class="col-xs-2 text-right">Tên sự kiện:</label>
        <div class="col-xs-10">
            <strong><?php echo $model->title; ?></strong>
        </div>
    </div>
    <div class="form-group">
        <label class="col-xs-2 text-right">Loại sự kiện:</label>
        <div class="col-xs-10">
            <strong><?php echo $model->getTicket(); ?></strong>
        </div>
    </div>
    <div class="form-group">
        <label class="col-xs-2 text-right">Vé sự kiện:</label>
        <div class="col-xs-10">
            <!-- Event Ticket -->
            <div class="event-tickets">
            <?php if (!empty($model->tickets)) : ?>
            <?php foreach ($model->tickets as $data): ?>
                <input type="hidden" name="OrderTickets[ticket_id][]" value="<?php echo $data->id; ?>" />
                <input type="hidden" name="OrderTickets[price][]" value="<?php echo number_format($data->price, 0, ',', ''); ?>" />
                <div class="form-group">
                    <div class="col-xs-3 ticket-title">
                        <input type="text" class="form-control input-sm" placeholder="Loại vé" name="EventTickets[title][]" id="EventTickets[title]" value="<?php echo $data->title; ?>" disabled />
                    </div>
                    <label class="control-label ticket-price-label col-xs-2">Giá vé</label>
                    <div class="col-xs-3 input-icon right ticket-price">
                        <span class="">VNĐ</span>
                        <input type="text" class="form-control input-sm text-right" placeholder="Giá vé" name="EventTickets[price][]" id="OrderTickets[price]" value="<?php echo number_format($data->price, 0, ',', '.'); ?>" disabled />
                    </div>
                    <label class="control-label col-xs-2 text-right">Số lượng</label>
                    <div class="col-xs-2">
                        <input type="text" class="form-control input-sm text-right" placeholder="Số lượng" name="OrderTickets[quantity][]" id="OrderTickets[quantity]" value="0" />
                    </div>
                </div>
            <?php endforeach; ?>
            <?php else: ?>
                <strong>Liên hệ</strong>
            <?php endif; ?>
            </div>
        </div>
    </div>
    <?php echo $form->hiddenField($order, 'member_id', array('value'=>Yii::app()->user->id)); ?>
</fieldset>
<fieldset>
    <legend>Thông tin người mua</legend>
    <!-- Order Buyer -->
    <div class="form-group">
        <?php echo $form->labelEx($orderBuyer, 'lname', array('class'=>'control-label col-xs-2')); ?>
        <div class="col-xs-5">
            <?php echo $form->textField($orderBuyer, 'lname', array('class'=>'form-control input-sm', 'placeholder'=>'Họ và tên đệm')); ?>
            <?php echo $form->error($orderBuyer, 'lname'); ?>

        </div>
        <div class="col-xs-5">
            <?php echo $form->textField($orderBuyer, 'fname', array('class'=>'form-control input-sm', 'placeholder'=>'Tên')); ?>
            <?php echo $form->error($orderBuyer, 'fname'); ?>

        </div>
    </div>
    <div class="form-group">
        <?php echo $form->labelEx($orderBuyer, 'email', array('class'=>'control-label col-xs-2')); ?>
        <div class="col-xs-10">
            <?php echo $form->textField($orderBuyer, 'email', array('class'=>'form-control input-sm', 'placeholder'=>'Địa chỉ Email')); ?>
            <?php echo $form->error($orderBuyer, 'email'); ?>
        </div>
    </div>
    <div class="form-group">
        <?php echo $form->labelEx($orderBuyer, 'phone', array('class'=>'control-label col-xs-2')); ?>
        <div class="col-xs-5">
            <?php echo $form->textField($orderBuyer, 'phone', array('class'=>'form-control input-sm', 'placeholder'=>'Số điện thoại')); ?>
            <?php echo $form->error($orderBuyer, 'phone'); ?>
            <div id="id_phone_1" style="display:none;" class="errorMessage">Lỗi ! Số điện thoại không đúng định dạng </div>
        </div>
        <div class="col-xs-5">
            <?php echo $form->textField($orderBuyer, 'altphone', array('class'=>'form-control input-sm', 'placeholder'=>'Số điện thoại khác')); ?>
            <div id="id_phone_2" style="display:none;" class="errorMessage">Lỗi ! Số điện thoại không đúng định dạng </div>
        </div>
    </div>
    <div class="form-group">
        <?php echo $form->labelEx($orderBuyer, 'address', array('class'=>'control-label col-xs-2')); ?>
        <div class="col-xs-10">
            <?php echo $form->textField($orderBuyer, 'address', array('class'=>'form-control input-sm', 'placeholder'=>'Địa chỉ')); ?>
            <?php echo $form->error($orderBuyer, 'address'); ?>
        </div>
    </div>
    <div class="form-group">
        <div class="col-xs-5 col-xs-offset-2">
            <?php echo $form->textField($orderBuyer, 'ward', array('class'=>'form-control input-sm', 'placeholder'=>'Phường/Xã')); ?>
        </div>
        <div class="col-xs-5">
            <?php echo $form->textField($orderBuyer, 'district', array('class'=>'form-control input-sm', 'placeholder'=>'Quận/Huyện')); ?>
        </div>
    </div>
    <div class="form-group">
        <div class="col-xs-5 col-xs-offset-2">
            <?php echo $form->textField($orderBuyer, 'city', array('class'=>'form-control input-sm', 'placeholder'=>'Tỉnh/Thành phố', 'value'=>$user->city)); ?>
        </div>
        <div class="col-xs-5">
            <?php echo $form->dropDownList($orderBuyer, 'country', $countries, array('class'=>'form-control input-sm')); ?>
        </div>
    </div>
</fieldset>
<fieldset>
    <legend>Thông tin người nhận <input type="checkbox" id="checkbox_buyer"><span style="font-style: italic;font-size: 11px;" >(lựa chọn nếu người nhận là người mua)</span></legend>
    <!-- Order Buyer -->
    <div class="form-group">
        <?php echo $form->labelEx($orderReceiver, 'lname', array('class'=>'control-label col-xs-2')); ?>
        <div class="col-xs-5">
            <?php echo $form->textField($orderReceiver, 'lname', array('class'=>'form-control input-sm', 'placeholder'=>'Họ và tên đệm')); ?>
            <?php echo $form->error($orderReceiver, 'lname'); ?>

        </div>
        <div class="col-xs-5">
            <?php echo $form->textField($orderReceiver, 'fname', array('class'=>'form-control input-sm', 'placeholder'=>'Tên')); ?>
            <?php echo $form->error($orderReceiver, 'fname'); ?>

        </div>
    </div>
    <div class="form-group">
        <?php echo $form->labelEx($orderReceiver, 'email', array('class'=>'control-label col-xs-2')); ?>
        <div class="col-xs-10">
            <?php echo $form->textField($orderReceiver, 'email', array('class'=>'form-control input-sm', 'placeholder'=>'Địa chỉ Email')); ?>
            <?php echo $form->error($orderReceiver, 'email'); ?>
        </div>
    </div>
    <div class="form-group">
        <?php echo $form->labelEx($orderReceiver, 'phone', array('class'=>'control-label col-xs-2')); ?>
        <div class="col-xs-5">
            <?php echo $form->textField($orderReceiver, 'phone', array('class'=>'form-control input-sm', 'placeholder'=>'Số điện thoại')); ?>
            <?php echo $form->error($orderReceiver, 'phone'); ?>
            <div id="id_phone_3" style="display:none;" class="errorMessage">Lỗi ! Số điện thoại không đúng định dạng </div>
        </div>
        <div class="col-xs-5">
            <?php echo $form->textField($orderReceiver, 'altphone', array('class'=>'form-control input-sm', 'placeholder'=>'Số điện thoại khác')); ?>
            <div id="id_phone_4" style="display:none;" class="errorMessage">Lỗi ! Số điện thoại không đúng định dạng </div>
        </div>
    </div>
    <div class="form-group">
        <?php echo $form->labelEx($orderReceiver, 'address', array('class'=>'control-label col-xs-2')); ?>
        <div class="col-xs-10">
            <?php echo $form->textField($orderReceiver, 'address', array('class'=>'form-control input-sm', 'placeholder'=>'Địa chỉ')); ?>
            <?php echo $form->error($orderReceiver, 'address'); ?>
        </div>
    </div>
    <div class="form-group">
        <div class="col-xs-5 col-xs-offset-2">
            <?php echo $form->textField($orderReceiver, 'ward', array('class'=>'form-control input-sm', 'placeholder'=>'Phường/Xã')); ?>
        </div>
        <div class="col-xs-5">
            <?php echo $form->textField($orderReceiver, 'district', array('class'=>'form-control input-sm', 'placeholder'=>'Quận/Huyện')); ?>
        </div>
    </div>
    <div class="form-group">
        <div class="col-xs-5 col-xs-offset-2">
            <?php echo $form->textField($orderReceiver, 'city', array('class'=>'form-control input-sm', 'placeholder'=>'Tỉnh/Thành phố', 'value'=>$user->city)); ?>
        </div>
        <div class="col-xs-5">
            <?php echo $form->dropDownList($orderReceiver, 'country', $countries, array('class'=>'form-control input-sm')); ?>
        </div>
    </div>
    <div class="form-group">
        <?php echo $form->labelEx($orderReceiver, 'note', array('class'=>'control-label col-xs-2')); ?>
        <div class="col-xs-10">
            <?php echo $form->textArea($orderReceiver, 'note', array('class'=>'form-control input-sm', 'placeholder'=>'Ghi chú đặt vé', 'rows'=>5)); ?>
            <?php echo $form->error($orderReceiver, 'note'); ?>
        </div>
    </div>
</fieldset>
<div class="form-group">
    <div class="col-xs-12">
        <div class="text-right">
            <p>Vé sự kiện của quý khách sẽ được chúng tôi liên hệ trong thời gian sớm nhất.</p>
        </div>
        <button type="submit" id="button_submit" class="btn btn-create pull-right btn-event" onclick="$('.loader').show();">Đặt vé sự kiện</button>
        <a id="submit_eror" style="display:none" class="btn btn-create pull-right btn-event" onclick="alert('Bạn chưa nhập đúng thông tin'); return false;">Đặt vé sự kiện</a>
    </div>
</div>
<?php $this->endWidget(); ?>

<script type="text/javascript">
$(document).ready(function() {
    //set initial state.
    $('#checkbox_buyer').val($(this).is(':checked'));

    $('#checkbox_buyer').change(function() {
        if($(this).is(":checked")) {
            $("#OrderReceivers_lname").val($("#OrderBuyers_lname").val());
            $("#OrderReceivers_fname").val($("#OrderBuyers_fname").val());
            $("#OrderReceivers_email").val($("#OrderBuyers_email").val());
            $("#OrderReceivers_phone").val($("#OrderBuyers_phone").val());
            $("#OrderReceivers_altphone").val($("#OrderBuyers_altphone").val());
            $("#OrderReceivers_address").val($("#OrderBuyers_address").val());
            $("#OrderReceivers_ward").val($("#OrderBuyers_ward").val());
            $("#OrderReceivers_district").val($("#OrderBuyers_district").val());
            $("#OrderReceivers_city").val($("#OrderBuyers_city").val());
            $("#OrderReceivers_country").val($("#OrderBuyers_country").val());
            $("#OrderReceivers_note").val($("#OrderBuyers_note").val());
        }
        $('#checkbox_buyer').val($(this).is(':checked'));        
    });
});
</script>
<script type="text/javascript">
$(document).ready(function(){
    var regPhone  = /^((\+[1-9]{1,4}[ \-]*)|(\([0-9]{2,3}\)[ \-]*)|([0-9]{2,4})[ \-]*)*?[0-9]{3,4}?[ \-]*[0-9]{3,4}?$/;
    $("#OrderBuyers_phone").change(function(){
        if(!regPhone.test($(this).val())){
                $("#id_phone_1").show();
                $("#button_submit").hide();
                $("#submit_eror").show();
            }else{
                $("#id_phone_1").hide();
                $("#button_submit").show();
                $("#submit_eror").hide();
            }
    });
    $("#OrderBuyers_altphone").change(function(){
        if(!regPhone.test($(this).val())){
                $("#id_phone_2").show();
                $("#button_submit").hide();
                $("#submit_eror").show();
            }else{
                $("#id_phone_2").hide();
                $("#button_submit").show();
                $("#submit_eror").hide();
            }
    });
    $("#OrderReceivers_phone").change(function(){
        if(!regPhone.test($(this).val())){
                $("#id_phone_3").show();
                $("#button_submit").hide();
                $("#submit_eror").show();
            }else{
                $("#id_phone_3").hide();
                $("#button_submit").show();
                $("#submit_eror").hide();
            }
    });
    $("#OrderReceivers_altphone").change(function(){
        if(!regPhone.test($(this).val())){
                $("#id_phone_4").show();
                $("#button_submit").hide();
                $("#submit_eror").show();
            }else{
                $("#id_phone_4").hide();
                $("#button_submit").show();
                $("#submit_eror").hide();
            }
    });
});
</script>